home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPMORE.ZIP / APPEXEC.C < prev    next >
C/C++ Source or Header  |  1992-08-17  |  5KB  |  174 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <shellapi.h>
  4. #include <stdarg.h>
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <direct.h>
  8. #include <string.h>
  9. #include "appmore.h"
  10.  
  11. /*--------------------------------------------------------------------------*/
  12. /* FUNCTION: ProgExec(LPSTR lpCmdLine, int nCmdShow)                */
  13. /*                                        */
  14. /* PURPOSE:  changes current drive & directory and executes a program        */
  15. /*--------------------------------------------------------------------------*/
  16. BOOL PASCAL ProgExec(HWND hWndParent, LPSTR lpszFile, LPSTR lpszParams, LPSTR lpszDir, int nCmdShow)
  17.     {
  18.     UINT ExecStatus;
  19.     UINT ShowMode[3] = {SW_SHOWNORMAL, SW_SHOWMAXIMIZED, SW_SHOWMINIMIZED};
  20.  
  21.     // show maximum sized files as normal, resizing is done later
  22.     if(nCmdShow == 3)
  23.     nCmdShow = 0;
  24.     // execute file
  25.     ExecStatus = ShellExecute(hWndParent, "open", lpszFile, lpszParams, lpszDir, ShowMode[nCmdShow]);
  26.     if(ExecStatus <= 32)
  27.     {
  28.     ExecuteErrorHandle(ExecStatus);
  29.     return FALSE;
  30.     }
  31.     else
  32.     return TRUE;
  33.     }
  34.  
  35.  
  36. /*---------------------------------------------------------------------------/
  37.    Function : StartOrCloseProgram()
  38. /---------------------------------------------------------------------------*/
  39. VOID PASCAL StartOrCloseProgram(int iClose)
  40.     {
  41.     CheckProgStatus();
  42.     if(AppButton[iClose].ProgStatus == NOTALIVE || !AppButton[iClose].Close)
  43.     {
  44.     iActive = iClose+1;
  45.     if(AppSound.EnableSound != 0)
  46.         if(stricmp(AppSound.ProgramStart, "<none>") != 0)
  47.         sndPlaySound(AppSound.ProgramStart, SND_ASYNC | SND_NODEFAULT);
  48.     ProgExec(hWndMain, (LPSTR)AppButton[iClose].ProgName, (LPSTR)AppButton[iClose].Params, (LPSTR)AppButton[iClose].StartDir, AppButton[iClose].ShowMode);
  49.     if(AppSystem.OneLaunch)
  50.         SendMessage(hWndMain, WM_DESTROY, 0, 0L);
  51.     }
  52.     else
  53.     {
  54.     if(IsWindow(AppButton[iClose].hWndApp))    //if program still exists, kill it.
  55.         {
  56.         if(AppSound.EnableSound != 0)
  57.         if(stricmp(AppSound.ProgramClose, "<none>") != 0)
  58.             sndPlaySound(AppSound.ProgramClose, SND_ASYNC | SND_NODEFAULT);
  59.         if(CloseApp(AppButton[iClose].hWndApp))
  60.         AppButton[iClose].ProgStatus = NOTALIVE;
  61.         InvalidateRect(hWndCurrentButton, (LPRECT) NULL, FALSE);
  62.         UpdateWindow(hWndCurrentButton);
  63.         }
  64.     else        // program doesn't exist anymore, start it again.
  65.         {
  66.         iActive = iClose+1;
  67.         if(AppSound.EnableSound != 0)
  68.         if(stricmp(AppSound.ProgramStart, "<none>") != 0)
  69.             sndPlaySound(AppSound.ProgramStart, SND_ASYNC | SND_NODEFAULT);
  70.         ProgExec(hWndMain, (LPSTR)AppButton[iClose].ProgName, (LPSTR)AppButton[iClose].Params, (LPSTR)AppButton[iClose].StartDir, AppButton[iClose].ShowMode);
  71.         }
  72.     }
  73.     }
  74.  
  75. /*---------------------------------------------------------------------------/
  76. /                                         /
  77. /  Function : CheckProgStatus()                          /
  78. /                                         /
  79. /  Purpose  : Updates the status of a program to the current status.         /
  80. /                                         /
  81. /---------------------------------------------------------------------------*/
  82. VOID PASCAL CheckProgStatus(VOID)
  83.     {
  84.     int iCheck;
  85.  
  86.     for(iCheck=0;iCheck<AppWindow.nButtons;iCheck++)
  87.     {
  88.     if(AppButton[iCheck].ProgStatus == ALIVE)       // AppMore thinks app[i] exists
  89.         {
  90.         if(!IsWindow(AppButton[iCheck].hWndApp))       // app[i] doesn't exists anymore
  91.         {
  92.         AppButton[iCheck].ProgStatus = NOTALIVE;   // AppMore knows that now
  93.         InvalidateRect(hWndButton[iCheck+1], (LPRECT) NULL, FALSE);
  94.         }
  95.         }
  96.     }
  97.     }
  98.  
  99. /*--------------------------------------------------------------------------*/
  100. VOID ExecuteErrorHandle(int iError)
  101.     {
  102.     switch(iError)
  103.     {
  104.     case 0:
  105.         strcpy(szBuffer,"Out of memory.");
  106.         break;
  107.  
  108.     case 2:
  109.         strcpy(szBuffer,"File not found.");
  110.         break;
  111.  
  112.     case 3:
  113.         strcpy(szBuffer,"Path not found.");
  114.         break;
  115.  
  116.     case 5:
  117.         strcpy(szBuffer,"Attempt to dynamically link to a task.");
  118.         break;
  119.  
  120.     case 6:
  121.         strcpy(szBuffer,"Library requires separate data segments\nfor each task.");
  122.         break;
  123.  
  124.     case 8:
  125.         strcpy(szBuffer,"Insufficient memory to start application.");
  126.         break;
  127.  
  128.     case 10:
  129.         strcpy(szBuffer,"Incorrect Windows version.");
  130.         break;
  131.  
  132.     case 11:
  133.         strcpy(szBuffer,"Invalid .EXE file.");
  134.         break;
  135.  
  136.     case 12:
  137.         strcpy(szBuffer,"OS/2 application.");
  138.         break;
  139.  
  140.     case 13:
  141.         strcpy(szBuffer,"DOS 4.0 application.");
  142.         break;
  143.  
  144.     case 14:
  145.         strcpy(szBuffer,"Unknown .EXE type.");
  146.         break;
  147.  
  148.     case 15:
  149.         strcpy(szBuffer,"Attempt to load a Windows 2.x .EXE in protected mode.");
  150.         break;
  151.  
  152.     case 16:
  153.         strcpy(szBuffer,"Attempt to load a 2nd instance of\nan .EXE with writeable data.");
  154.         break;
  155.  
  156.     case 17:
  157.         strcpy(szBuffer,"Attempt to link already used nonshareable DLLs\nin large-frame EMS mode.");
  158.         break;
  159.  
  160.     case 19:
  161.         strcpy(szBuffer,"Attempt to load compressed .EXE file.");
  162.         break;
  163.  
  164.     case 20:
  165.         strcpy(szBuffer,"Invalid DLL file.");
  166.         break;
  167.  
  168.     default:
  169.         sprintf(szBuffer,"Unknown File Execution Error (%d)",iError);
  170.         break;
  171.     }
  172.     OkMsgBox("AppMore - File Execution", "%s", szBuffer);
  173.     }
  174.